package com.denlaku.longan.http;

import java.util.Map;

import com.denlaku.longan.vo.User;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.github.pagehelper.Page;

/**
 * controller分页错误返回对象
 *
 * @param <T> 数据类型
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
class PageSuccess<T> implements Return<T> {

    private final boolean status;
    private T data;
    private Object ext;
    private Map<Long, User> umap;
    private String code;
    private String msg;
    private long total;
    private int page;
    private int pages;

    public PageSuccess(T data, String msg) {
        super();
        this.status = true;
        this.data = data;
        this.msg = msg;
        if (data instanceof Page<?>) {
            Page<?> tmp = (Page<?>) data;
            this.total = tmp.getTotal();
            this.page = tmp.getPageNum();
            this.pages = tmp.getPages();
        }
    }

    public boolean isStatus() {
        return status;
    }

    @Override
    public T getData() {
        return data;
    }

    public Return<T> setData(T data) {
        this.data = data;
        return this;
    }

    public Object getExt() {
        return ext;
    }

    @Override
    public Return<T> setExt(Object ext) {
        this.ext = ext;
        return this;
    }

    @Override
    public Map<Long, User> getUmap() {
        return umap;
    }

    @Override
    public Return<T> setUmap(Map<Long, User> umap) {
        this.umap = umap;
        return this;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    @Override
    public Return<T> setCode(String code) {
        this.code = code;
        return this;
    }
}
